/////read in counterfactual simulated data

qui{
forval i = 1/3{

**no behavioreal resopnse
import delimited "$dir/Model/Simulated_data/simulated_data_cfact_movecosts_nob_amen_`i'.csv", clear
gen uniqid = _n
keep uniqid v26 v14 v24 v22
ren v26 pctile_nob
ren v24 faminc_nob
ren v22 util_nob
tempfile nob
save `nob'

**full behavioral response
import delimited "$dir/Model/Simulated_data/simulated_data_cfact_movecosts_amen_`i'.csv", clear
gen uniqid = _n
keep uniqid v9 v12 v8
ren v12 pctile_movecost
tempfile movecost
save `movecost'

//baseline
import delimited "$dir/Model/Simulated_data/simulated_data_base_amen_`i'.csv", clear
gen uniqid = _n

keep uniqid v1 v25 v26 v14 v24 v22
ren v1 statefips
ren v26 pctile
ren v24 faminc
keep if v25<50
ren v22 util

merge 1:1 uniqid using `nob', keep(match) nogen
merge 1:1 uniqid using `movecost', keep(match) nogen

ren v14 weight
collapse (mean) util* pctile* faminc* weight, by(statefips)
save "$temp/cfact_move_data_amen_`i'", replace



use "$temp/cfact_move_data_amen_`i'", clear

gen diff_nob_amen_1 = pctile_nob - pctile
gen diff_movecost_amen_1 = pctile_movecost-pctile
keep statefips diff*

merge 1:1 statefips using "$temp/cfact_move_data", keep(match) nogen

gen diff_nob = pctile_nob - pctile
gen diff_movecost = pctile_movecost-pctile
gen diff_decomp_1 = pctile_decomp_1 - pctile
gen diff_decomp_2 = pctile_decomp_2 - pctile

noi corr diff_movecost*
noi su diff_movecost*
}
}